package com.umerclass.ui.anmo;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.umerclass.AppDroid;
import com.umerclass.R;
import com.umerclass.bean.anmo.TiXianDetailsBean;
import com.umerclass.frame.model.InfoResult;
import com.umerclass.frame.ui.activity.BaseActivity;
import com.umerclass.frame.ui.recycleview.PullLoadMoreRecyclerView;
import com.umerclass.frame.ui.recycleview.listener.DataStateListener;
import com.umerclass.frame.ui.recycleview.listener.OptListener;
import com.umerclass.frame.ui.statelayout.StateLayout;
import com.umerclass.ui.anmo.adapter.TiXianDetailsAdapter;
import com.umerclass.utils.ItemClickSupport;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;

public class TiXianDetailsActivity extends BaseActivity implements DataStateListener,
        PullLoadMoreRecyclerView.PullLoadMoreListener, OptListener {
    @BindView(R.id.linear_back)
    LinearLayout linearBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.swipeRefreshLayout)
    SwipeRefreshLayout swipeRefreshLayout;
    @BindView(R.id.pullLoadMoreRecyclerView)
    PullLoadMoreRecyclerView pullLoadMoreRecyclerView;
    @BindView(R.id.state_layout)
    StateLayout stateLayout;
    private TiXianDetailsAdapter tiXianDetailsAdapter;
    private List<TiXianDetailsBean> infos = new ArrayList<>();

    @Override
    public boolean isImmersionBarEnabled() {
        return false;
    }

    @Override
    public boolean isSupportSwipeBack() {
        return false;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_tixian_details;
    }

    @Override
    public void init() {
        initView();
    }

    @Override
    public void loadData() {
        getTeams();
    }

    @OnClick({R.id.linear_back})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.linear_back:
                finish();
                break;
            default:
                break;
        }
    }

    private void getTeams(){
       /* OkEntityRequest<PerformanceListBean> request = new OkEntityRequest<>(R.id.myPerformanceList,
                Constants.myPerformanceList, PerformanceListBean.class);
        request.addParams("userId", AppDroid.getInstance().getUserOtherBean().getUserId());
        //0入账 1出账
        request.addParams("operation", 0);
        request.addParams("startDayTime", "");
        request.addParams("endDayTime", "");
        request.addParams("page",performanceAdapter.getPage());
        request.addParams("rows",10);
        request.addHeadParams("userType",AppDroid.getInstance().getUserOtherBean().getUserType());
        request.addHeadParams("userToken",AppDroid.getInstance().getUserOtherBean().getToken());
        requestOkhttpEntity(request);*/
    }

    @Override
    protected void onSuccess(int what, InfoResult t) {
        switch (what) {
            case R.id.myPerformanceList:
                infos = (List<TiXianDetailsBean>) t.getT();
                tiXianDetailsAdapter.addDataSource(infos, t);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onFail(int what, InfoResult t) {
        switch (what) {
            case R.id.myPerformanceList:
                swipeRefreshLayout.setRefreshing(false);
                showToast(t.getDesc());
                break;
            default:
                break;
        }
    }

    @Override
    public void onRefresh() {
        tiXianDetailsAdapter.reset();
        loadData();
    }

    @Override
    public void onLoadMore() {
        loadData();
    }

    @Override
    public void onDataState(int flag) {
        //1:没有网络 2:没有数据 3:获取数据失败 4:显示内容
        switch (flag) {
            case 1:
                stateLayout.showNoNetworkView();
                break;
            case 2:
                stateLayout.showEmptyView();
                break;
            case 3:
                stateLayout.showErrorView();
                break;
            case 4:
                stateLayout.showContentView();
                break;
            default:
                break;
        }
    }

    @Override
    public void onOptClick(View view, Object object) {

    }

    private void initView() {

        stateLayout.setRefreshListener(new StateLayout.OnViewRefreshListener() {
            @Override
            public void refreshClick() {
                loadData();
            }

            @Override
            public void loginClick() {
            }
        });
        pullLoadMoreRecyclerView.init(recyclerView, swipeRefreshLayout);
        tiXianDetailsAdapter = new TiXianDetailsAdapter(TiXianDetailsActivity.this, R.layout.activity_tixian_details_item, pullLoadMoreRecyclerView,
                this, this);
        pullLoadMoreRecyclerView.setAdapterTwo(tiXianDetailsAdapter);
        pullLoadMoreRecyclerView.setOnPullLoadMoreListener(this);
        // 设置颜色属性的时候一定要注意是引用了资源文件还是直接设置16进制的颜色，因为都是int值容易搞混
        // 设置下拉进度的背景颜色，默认就是白色的
        swipeRefreshLayout.setProgressBackgroundColorSchemeResource(android.R.color.white);
        // 设置下拉进度的主题颜色
        swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorAccent, R.color.colorAccent);
        // 下拉时触发SwipeRefreshLayout的下拉动画，动画完毕之后就会回调这个方法

        //单击
        ItemClickSupport.addTo(pullLoadMoreRecyclerView.getRecyclerView())
                .setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
                    @Override
                    public void onItemClicked(RecyclerView recyclerView, int position, View v) {
                    }
                });
        //长按
        ItemClickSupport.addTo(pullLoadMoreRecyclerView.getRecyclerView()).setOnItemLongClickListener(new ItemClickSupport.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClicked(RecyclerView recyclerView, int position, View v) {
                return false;
            }
        });
    }
}
